/*
 * Copyright 2020-2021 redragon.dongbin
 *
 * This file is part of redragon-erp/赤龙ERP.

 * redragon-erp/赤龙ERP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * redragon-erp/赤龙ERP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with redragon-erp/赤龙ERP.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.erp.common.je.dao.model;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.redragon.commons.math.MoneyUtil;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity(name="glJeHeadCommon")
@Table(name="gl_je_head", schema="erp")
@DynamicInsert(true)
@DynamicUpdate(true)
public class GLJeHead implements java.io.Serializable {

    //serialVersionUID
    private static final long serialVersionUID = 1L;

    //Constructors
    public GLJeHead() {
    }
    
    //Fields
    
    //日记账头id
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "je_head_id", unique = true, nullable = false)
    private Integer jeHeadId;
    
    public Integer getJeHeadId() {
        return this.jeHeadId;
    }
    public void setJeHeadId(Integer jeHeadId) {
        this.jeHeadId = jeHeadId;
    }
    
    //日记账头编码
    //@NotBlank(message="日记账编码不能为空")
    @Column(name = "je_head_code", unique = true, nullable = false, length = 45)
    private String jeHeadCode;
    
    public String getJeHeadCode() {
        return this.jeHeadCode;
    }
    public void setJeHeadCode(String jeHeadCode) {
        this.jeHeadCode = jeHeadCode;
    }
    
    //日记账名称
    @NotBlank(message="日记账名称不能为空")
    @Column(name = "je_name", unique = false, nullable = false, length = 45)
    private String jeName;
    
    public String getJeName() {
        return this.jeName;
    }
    public void setJeName(String jeName) {
        this.jeName = jeName;
    }
    
    //日记账类型（手工MANUAL、子分类账SLA、导入IMPORT）
    @NotBlank(message="日记账类型不能为空")
    @Column(name = "je_type", unique = false, nullable = false, length = 45)
    private String jeType;
    
    public String getJeType() {
        return this.jeType;
    }
    public void setJeType(String jeType) {
        this.jeType = jeType;
    }
    
    //日记账来源（与子分类账单据类型同源）
    @Column(name = "je_source", unique = false, nullable = false, length = 45)
    private String jeSource;
    
    public String getJeSource() {
        return this.jeSource;
    }
    public void setJeSource(String jeSource) {
        this.jeSource = jeSource;
    }
    
    //日记账日期
    @NotNull(message="日记账日期不能为空")
    @Column(name = "je_date", unique = false, nullable = false)
    private Date jeDate;
    
    public Date getJeDate() {
        return this.jeDate;
    }
    public void setJeDate(Date jeDate) {
        this.jeDate = jeDate;
    }
    
    //备注
    @Column(name = "je_desc", unique = false, nullable = true, length = 200)
    private String jeDesc;
    
    public String getJeDesc() {
        return jeDesc;
    }
    public void setJeDesc(String jeDesc) {
        this.jeDesc = jeDesc;
    }

    //分类账簿编码
    @NotBlank(message="分类账簿编码不能为空")
    @Column(name = "ledger_code", unique = false, nullable = false, length = 45)
    private String ledgerCode;
    
    public String getLedgerCode() {
        return this.ledgerCode;
    }
    public void setLedgerCode(String ledgerCode) {
        this.ledgerCode = ledgerCode;
    }
    
    //币种
    @NotBlank(message="币种不能为空")
    @Column(name = "currency_code", unique = false, nullable = false, length = 45)
    private String currencyCode;
    
    public String getCurrencyCode() {
        return this.currencyCode;
    }
    public void setCurrencyCode(String currencyCode) {
        this.currencyCode = currencyCode;
    }
    
    //会计期间
    @NotBlank(message="会计期间不能为空")
    @Column(name = "period_name", unique = false, nullable = false, length = 45)
    private String periodName;
    
    public String getPeriodName() {
        return this.periodName;
    }
    public void setPeriodName(String periodName) {
        this.periodName = periodName;
    }
    
    //原始单据数量
    @NotNull(message="原始单据数量不能为空")
    @Column(name = "bill_num", unique = false, nullable = false)
    private Integer billNum;
    
    public Integer getBillNum() {
        return this.billNum;
    }
    public void setBillNum(Integer billNum) {
        this.billNum = billNum;
    }
    
    //过账状态（未过账Y、已过账N）
    @Column(name = "post_status", unique = false, nullable = false, length = 1)
    private String postStatus;
    
    public String getPostStatus() {
        return this.postStatus;
    }
    public void setPostStatus(String postStatus) {
        this.postStatus = postStatus;
    }
    
    //冲销凭证编码
    @Column(name = "reverse_je_head_code", unique = false, nullable = true, length = 45)
    private String reverseJeHeadCode;
    
    public String getReverseJeHeadCode() {
        return reverseJeHeadCode;
    }
    public void setReverseJeHeadCode(String reverseJeHeadCode) {
        this.reverseJeHeadCode = reverseJeHeadCode;
    }
    
    //子分类账头编码
    @Column(name = "voucher_head_code", unique = false, nullable = true, length = 45)
    private String voucherHeadCode;
    
    public String getVoucherHeadCode() {
        return this.voucherHeadCode;
    }
    public void setVoucherHeadCode(String voucherHeadCode) {
        this.voucherHeadCode = voucherHeadCode;
    }

    //版本
    @Column(name = "version", unique = false, nullable = false)
    private Integer version;
    
    public Integer getVersion() {
        return this.version;
    }
    public void setVersion(Integer version) {
        this.version = version;
    }
    
    //状态（新建NEW，确认CONFIRM，变更ALTER，取消CANCEL，冲销REVERSE）
    @Column(name = "status", unique = false, nullable = false, length = 10)
    private String status;
    
    public String getStatus() {
        return this.status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    
    //审批状态（未提交UNSUBMIT、已提交SUBMIT、已审批APPROVE、已驳回REJECT）
    @Column(name = "approve_status", unique = false, nullable = false, length = 10)
    private String approveStatus;
    
    public String getApproveStatus() {
        return this.approveStatus;
    }
    public void setApproveStatus(String approveStatus) {
        this.approveStatus = approveStatus;
    }
    
    //制单人
    @Column(name = "staff_code", unique = false, nullable = false, length = 45)
    private String staffCode;
    
    public String getStaffCode() {
        return this.staffCode;
    }
    public void setStaffCode(String staffCode) {
        this.staffCode = staffCode;
    }
    
    //制单部门
    @Column(name = "department_code", unique = false, nullable = false, length = 45)
    private String departmentCode;
    
    public String getDepartmentCode() {
        return this.departmentCode;
    }
    public void setDepartmentCode(String departmentCode) {
        this.departmentCode = departmentCode;
    }
    
    //创建时间
    @Column(name = "created_date", unique = false, nullable = false)
    private Date createdDate;
    
    public Date getCreatedDate() {
        return this.createdDate;
    }
    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }
    
    //创建人
    @Column(name = "created_by", unique = false, nullable = false, length = 45)
    private String createdBy;
    
    public String getCreatedBy() {
        return this.createdBy;
    }
    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }
    
    //最后修改时间
    @Column(name = "last_updated_date", unique = false, nullable = true)
    private Date lastUpdatedDate;
    
    public Date getLastUpdatedDate() {
        return this.lastUpdatedDate;
    }
    public void setLastUpdatedDate(Date lastUpdatedDate) {
        this.lastUpdatedDate = lastUpdatedDate;
    }
    
    //最后修改人
    @Column(name = "last_updated_by", unique = false, nullable = true, length = 45)
    private String lastUpdatedBy;
    
    public String getLastUpdatedBy() {
        return this.lastUpdatedBy;
    }
    public void setLastUpdatedBy(String lastUpdatedBy) {
        this.lastUpdatedBy = lastUpdatedBy;
    }
    
    //组织机构
    @Column(name = "org_code", unique = false, nullable = false, length = 10)
    private String orgCode;
    
    public String getOrgCode() {
        return this.orgCode;
    }
    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }
    
    //法人主体
    @Column(name = "legal_code", unique = false, nullable = false, length = 45)
    private String legalCode;
    
    public String getLegalCode() {
        return this.legalCode;
    }
    public void setLegalCode(String legalCode) {
        this.legalCode = legalCode;
    }
    
    
    
    /*
     * 用于展示的字段
     */
    @Transient
    private String staffName;
    @Transient
    private String departmentName;
    @Transient
    private BigDecimal amount;
    @Transient
    private String amountDesc;
    @Transient
    private Double drAmount;
    @Transient
    private Double crAmount;
    @Transient
    private String[] drAmountArray;
    @Transient
    private String[] crAmountArray;

    public String getStaffName() {
        return staffName;
    }
    public void setStaffName(String staffName) {
        this.staffName = staffName;
    }
    public String getDepartmentName() {
        return departmentName;
    }
    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    public BigDecimal getAmount() {
        return amount;
    }
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }
    public String[] getDrAmountArray() {
        if(this.drAmount!=null) {
            if(this.drAmount!=0) {
                DecimalFormat df = new DecimalFormat("#.00");
                String temp = df.format(this.drAmount).replace(".", "");
                char[] tempChar = temp.toCharArray();
                
                int x = 0;
                String[] array = new String[11];
                for(int i=0;i<11;i++) {
                    int index = 11-temp.length();
                    if(i>=index) {
                        array[i] = String.valueOf(tempChar[x]);
                        x++;
                    }else {
                        array[i] = "";
                    }
                }
                return array;
            }else {
                String[] array = new String[11];
                for(int i=0;i<11;i++) {
                    array[i] = "";
                }
                return array;
            }
        }else {
            return new String[11];
        }
    }
    public void setDrAmountArray(String[] drAmountArray) {
        this.drAmountArray = drAmountArray;
    }
    public String[] getCrAmountArray() {
        if(this.crAmount!=null) {
            if(this.crAmount!=0) {
                DecimalFormat df = new DecimalFormat("#.00");
                String temp = df.format(this.crAmount).replace(".", "");
                char[] tempChar = temp.toCharArray();
                
                int x = 0;
                String[] array = new String[11];
                for(int i=0;i<11;i++) {
                    int index = 11-temp.length();
                    if(i>=index) {
                        array[i] = String.valueOf(tempChar[x]);
                        x++;
                    }else {
                        array[i] = "";
                    }
                }
                return array;
            }else {
                String[] array = new String[11];
                for(int i=0;i<11;i++) {
                    array[i] = "";
                }
                return array;
            }
        }else {
            return new String[11];
        }
        
    }
    public void setCrAmountArray(String[] crAmountArray) {
        this.crAmountArray = crAmountArray;
    }
    public String getAmountDesc() {
        try {
            String desc = MoneyUtil.toChineseMoney(this.amount.doubleValue());
            return desc;
        }catch(Exception e) {
            return "";
        }
    }
    public void setAmountDesc(String amountDesc) {
        this.amountDesc = amountDesc;
    }
    public Double getDrAmount() {
        return drAmount;
    }
    public void setDrAmount(Double drAmount) {
        this.drAmount = drAmount;
    }
    public Double getCrAmount() {
        return crAmount;
    }
    public void setCrAmount(Double crAmount) {
        this.crAmount = crAmount;
    }
    
}